/*
#include "ui_enabler.h"
#include "ui_manager.h"

#include "console/console.h"
#include "script/scripthelper.h"

#include "util/timer.h"				// log
#include "util/log.h"				// log
#include "util/common_macros.h"		// macros
#include "util/mmgr.h"		    

#include <cassert>

using namespace ui;
using namespace script;


UIEnabler::UIEnabler() :
	m_CurLevel(-1),
	m_pActivateCB(NULL),
	m_pvActivateData(NULL),
	m_pActivateFunc(NULL),
	m_pIDMapper(NULL)
{
}

UIEnabler::~UIEnabler()
{
}

UIEnabler& UIEnabler::Instance()
{
	static UIEnabler inst;
	return inst;
}

void UIEnabler::Load(const std::string& File, const std::string& Header)
{
	assert(!File.empty() && !Header.empty());
	m_UIList.clear();
	m_CurLevel = -1;

	LuaPlus::LuaState*	pScript = ScriptHelper::CreateLuaState();
	if (!ScriptHelper::DoFile(*pScript, File))
	{
		_LOG(MSG_ERROR, "Unable to load UIEnabler data from file " << File << "!");
		 LuaState::Destroy( pScript );
		return;
	} else
	{
		LuaPlus::LuaObject	Table = ScriptHelper::GetObj(*pScript, Header);
		if (Table.IsTable())
		{
			for (int i=0; i<Table.GetTableCount(); i++)
			{
				LuaPlus::LuaObject	Data = Table.GetByIndex(i+1);
				if (Data.IsTable())
				{
					std::string Panel	= ScriptHelper::GetTableString(Data, "Panel");
					std::string Widget	= ScriptHelper::GetTableString(Data, "Widget");
					if (Panel.empty() || Widget.empty()) continue;

					if (ui::UIWidget* pPanel	= UIManager::Instance().GetPanel(Panel))
					{
						UI_ENABLER_DATA d;
						d.pWidget				= pPanel->GetWidgetByName(Widget);
						d.MinLevel				= ScriptHelper::GetTableInt(Data, "MinLevel", -1);	
						d.DoColor				= ScriptHelper::GetTableFloat(Data, "DoColor", -1.0f);
						d.DoEnable				= ScriptHelper::GetTableBool(Data, "DoEnable");
						d.DoVisible				= ScriptHelper::GetTableBool(Data, "DoVisible");
						d.OnActivate			= ScriptHelper::GetTableString(Data, "OnActivate");

						if (d.pWidget && (d.MinLevel >= 0) && (d.DoEnable || d.DoVisible))
						{
							if (m_pIDMapper)
								d.ID			= m_pIDMapper->MapStringToID( ScriptHelper::GetTableString(Data, "ID") );
							else
								d.ID			= -1;

							if (d.DoColor >= 0.0f)
							{
								COLOR c = d.pWidget->GetColor();
								d.BaseColor.x = ColorGetRf(c);
								d.BaseColor.y = ColorGetGf(c);
								d.BaseColor.z = ColorGetBf(c);
								d.BaseColor.w = ColorGetAf(c);
								UTIL_CLAMP(d.DoColor, 0.0f, 1.0f);
							}

							d.IsActivated = true;
							m_UIList.push_back(d);
						}
					}
				}
			}
		}
	}
	LuaState::Destroy( pScript );
}

void UIEnabler::RefreshUI(int Level, bool ActivateEvent)
{
	for (int i = 0; i < (int)m_UIList.size(); i++)
	{
		UI_ENABLER_DATA& d = m_UIList[i];
		assert(d.pWidget);

		if ((-1 == Level) || (Level >= d.MinLevel))
		{
			if (d.DoEnable)			d.pWidget->SetIsActive(true);
			if (d.DoVisible)		d.pWidget->SetIsVisible(true);
			if (d.DoColor >= 0.0f)	d.pWidget->SetColor(d.BaseColor.x, d.BaseColor.y, d.BaseColor.z, d.BaseColor.w);

			if (ActivateEvent && !d.IsActivated && (Level > m_CurLevel))
			{
				// activate script
				if (!d.OnActivate.empty())
					console::Console::Instance().Do(d.OnActivate);

				// activate callback
				if (m_pActivateCB)
					m_pActivateCB(d.pWidget, d.ID, m_pvActivateData);

				// activate functor
				if (m_pActivateFunc)
					m_pActivateFunc(d.pWidget, d.ID);
			}

			d.IsActivated = true;
		}
		else
		{
			if (d.DoEnable)			d.pWidget->SetIsActive(false);
			if (d.DoVisible)		d.pWidget->SetIsVisible(false);
			if (d.DoColor >= 0.0f)	d.pWidget->SetColor(d.DoColor, d.DoColor, d.DoColor, d.BaseColor.w);
			
			d.IsActivated = false;
		}
	}

	if ((-1 == m_CurLevel) || (-1 != Level))
		m_CurLevel = Level;
}

bool UIEnabler::OnUIChanged(UIWidget* pWidget)
{
	for (int i = 0; i < (int)m_UIList.size(); i++)
	{
		UI_ENABLER_DATA& d = m_UIList[i];
		if (pWidget == d.pWidget)
		{
			// update new color
			if (d.DoColor >= 0)
			{
				COLOR c = d.pWidget->GetColor();
				d.BaseColor.x = ColorGetRf(c);
				d.BaseColor.y = ColorGetGf(c);
				d.BaseColor.z = ColorGetBf(c);
				d.BaseColor.w = ColorGetAf(c);
			}
			// anything else need updating?

			return true;
		}
	}
	return false;
}

bool UIEnabler::OnUIDeleted(UIWidget* pWidget)
{
	for (int i = 0; i < (int)m_UIList.size(); i++)
	{
		UI_ENABLER_DATA& d = m_UIList[i];
		if (pWidget == d.pWidget)
		{
			m_UIList.erase(m_UIList.begin()+i);
			return true;
		}
	}
	return false;
}

void UIEnabler::SetActivateEventCB(UIActivateEventCB pFunc, void* pvData)
{
	m_pActivateCB = pFunc;
	m_pvActivateData = pvData;
}



UIEnablerIDMapper::UIEnablerIDMapper()
{
	UIEnabler::Instance().SetIDMapper(this);
}

UIEnablerIDMapper::~UIEnablerIDMapper()
{
	UIEnabler::Instance().SetIDMapper(NULL);
}
*/
